Advertisement
Guest User

Untitled

a guest
Jun 18th, 2015
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.02 KB | None | 0 0
  1. // Learn more about F# at http://fsharp.net
  2. // See the 'F# Tutorial' project for more help.
  3.  
  4. open FSharp.Data
  5. open System
  6.  
  7.  
  8.  type Record = {voivoship : Option<int>;  district : Option<int>; community:Option<int>; rozd:Option<int>; name: Option<string>; addinf: Option<string> }
  9.  
  10.  type InputXml = XmlProvider<"Terc.xml">
  11.  
  12. [<EntryPoint>]
  13. let main argv =
  14.  
  15.     // createRecord sluzy tylko do stworzenia pustego rekordu ktory pozniej bedziemy wypelniac, domyslnie wartosci to poprostu None
  16.     let createRecord =
  17.         {
  18.             voivoship = None
  19.             district = None
  20.             community = None
  21.             rozd = None
  22.             name = None
  23.             addinf = None
  24.         }
  25.     //addCol bierze record i columne i na bazie tego tworzy nowy record z nowa wartoscia na bazie tej kolumny
  26.     let addCol name number string record =
  27.         match name with
  28.         | "WOJ" -> { record with voivoship = number }
  29.         | "POW" -> { record with district = number }
  30.         | "GMI" -> { record with community = number }
  31.         | "RODZ" -> { record with rozd = number }
  32.         | "NAZWA" -> { record with name = string }
  33.         | "NAZDOD" ->  { record with addinf = string }
  34.         | _ -> record
  35.  
  36.  
  37.     let tercs = InputXml.GetSample()
  38.    
  39.     // bierze liste column i odpala rekurencje po tej kolekcji, head to 1 element, tail to reszta elementow
  40.     let createRecordBasedOnRow cols =
  41.         let rec iterateCols record (cols:List<InputXml.Col>) =
  42.             match cols with
  43.                 | head::tail -> iterateCols (addCol head.Name head.Number head.String record) tail
  44.                 | [] -> record
  45.  
  46.         iterateCols createRecord cols
  47.  
  48.     let records =
  49.         seq {
  50.             for row in tercs.Rows do      
  51.                 yield (createRecordBasedOnRow (row.Cols |> Array.toList))
  52.             }
  53.  
  54.     for r in records do
  55.         match r.voivoship with
  56.         | None -> ()
  57.         | Some s -> printfn "%i" s
  58.        
  59.     Console.Read();
  60.     0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement